package com.anda.driver.locator;

import java.util.ArrayList;
import java.util.List;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class GoogleMapsActivity extends MapActivity {
	private MapController mapController;

	protected boolean isRouteDisplayed() {
		return false;
	}

	public void onCreate(Bundle paramBundle) {
		super.onCreate(paramBundle);
		setContentView(R.layout.maps);
		MapView mapView = (MapView) findViewById(R.id.mapview);
		mapView.setBuiltInZoomControls(true);
		Intent intent = getIntent();
		int i = (int) (1000000.0D * Double.parseDouble(intent
				.getStringExtra("lat")));
		int j = (int) (1000000.0D * Double.parseDouble(intent
				.getStringExtra("lng")));
		String str = intent.getStringExtra("gettime");
		List<Overlay> localList = mapView.getOverlays();
		MapItemizedOverlay localMapItemizedOverlay = new MapItemizedOverlay(
				getResources().getDrawable(R.drawable.ic_launcher), this);
		GeoPoint geoPoint = new GeoPoint(i, j);
		localMapItemizedOverlay.addOverlay(new OverlayItem(geoPoint,
				"Hola, Mundo!", str));
		localList.add(localMapItemizedOverlay);
		this.mapController = mapView.getController();
		this.mapController.setCenter(geoPoint);
		this.mapController.setZoom(15);
	}

	class MapItemizedOverlay extends ItemizedOverlay<OverlayItem> {
		private Context mContext;
		private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();

		public MapItemizedOverlay(Drawable defaultMarker) {
			super(boundCenterBottom(defaultMarker));
		}

		public MapItemizedOverlay(Drawable defaultMarker, Context context) {
			super(boundCenterBottom(defaultMarker));
			this.mContext = context;
		}

		public void addOverlay(OverlayItem overlayItem) {
			this.mOverlays.add(overlayItem);
			populate();
		}

		protected OverlayItem createItem(int i) {
			return (OverlayItem) this.mOverlays.get(i);
		}

		protected boolean onTap(int index) {
			OverlayItem localOverlayItem = (OverlayItem) this.mOverlays
					.get(index);
			AlertDialog.Builder localBuilder = new AlertDialog.Builder(
					this.mContext);
			localBuilder.setTitle(localOverlayItem.getTitle());
			localBuilder.setMessage(localOverlayItem.getSnippet());
			localBuilder.show();
			return true;
		}

		public int size() {
			return this.mOverlays.size();
		}
	}
}